package pandabay2.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import pandabay2.DAO.AuctionDAO;
import pandabay2.domain.Auction;
import pandabay2.domain.User;

/**
 * Servlet implementation class LoginServlet
 */
public class AuctionListServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AuctionListServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		try {
			System.out.println("In the Auction List Servlet");
			List<Auction> auctions;
			String tmpCategory = request.getParameter("category");
			if(tmpCategory.equals("Brettspiel"))
				auctions = AuctionDAO.findAll("Brettspiel");
			else if(tmpCategory.equals("Stofftier"))
				auctions = AuctionDAO.findAll("Stofftier");
			else if(tmpCategory.equals("Kinderbuch"))
				auctions = AuctionDAO.findAll("Kinderbuch");
			else {
				auctions = AuctionDAO.findAll("");
			}
			request.setAttribute("auctions", auctions);
			request.getRequestDispatcher("/AuctionList.jsp").forward(request, response);
		} catch (Throwable exc) {
			System.out.println(exc);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}
